package leetcode20210927;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LUYAO
 * Date: 2021-09-27
 * Time: 15:23
 */
public class TwoStackToOneQueue {
    public static void main(String[] args) {
        CQueue obj = new CQueue();
        obj.appendTail(2);
        obj.appendTail(3);
        int param_1 = obj.deleteHead();
        int param_2 = obj.deleteHead();
        System.out.println(param_1);
        System.out.println(param_2);

    }
}

class CQueue {
    private Stack<Integer> stack1;
    private Stack<Integer> stack2;

    public CQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void appendTail(int value) {
        stack1.push(value);
    }

    public int deleteHead() {
        if(!stack2.isEmpty()){
            return stack2.pop();
        }else {
            while(!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
            return stack2.isEmpty() ? -1 : stack2.pop();
        }

    }
}

